package com.yuma.rabbitmq.reconsumerproductor.controller;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RabbitController {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Transactional
    @RequestMapping("/send")
    public String transaction() {
        rabbitTemplate.convertAndSend("test_direct","key0","这是一条测试消息1");
        int i = 1/0;
        rabbitTemplate.convertAndSend("test_direct","key0","这是一条测试消息2");
        return "success";
    }
}
